<template>
  <el-row :gutter="20" class="afterHome">
    <el-col :span="24">
      <!-- 公司信息 -->
      <companyInfo ref="companyInfo" />
    </el-col>
    <el-col :span="12">
      <div class="box">
        <div class="area-header">
          <span class="area-header-title">{{ $t('还款计划') }}</span>
        </div>
        <div class="text item none-info" style="height: 300px;">
          <deal-servicing-plan-info ref="dealServicingPlanInfo" :is-component="true" :buss-id="businessId" />
        </div>
      </div>
    </el-col>
    <el-col :span="12">
      <div class="box">
        <div class="area-header">
          <span class="area-header-title">{{ $t('还本付息') }}</span>
        </div>
        <div class="text item none-info" style="height: 300px;">
          <deal-servicing-info ref="dealServicingInfo" :buss-id="businessId" />
        </div>
      </div>
    </el-col>
    <el-col :span="12">
      <div class="box">
        <div class="area-header">
          <span class="area-header-title">{{ $t('估值信息') }}</span>
          <el-link :underline="false" style="float: right;margin: 4px 0 0 10px;" @click="addDebtValuation">
            <i class="el-icon-plus" style="color: #007eff;" />
          </el-link>
          <div class="chartBtn">
            <el-select v-model="statistical" size="mini" style="width: 100px;margin-top: -4px;" @change="valuationHandler">
              <el-option :label="$t('按月统计')" value="month" />
              <el-option :label="$t('按季统计')" value="season" />
            </el-select>
          </div>
        </div>
        <div class="text item" style="height: 300px;">
          <lineChart v-if="chartData.datas.length > 0" height="100%" :chart-data="chartData" />
          <div v-else class="noneData">
            <div>
              <svg-icon icon-class="none" class-name="none-icon" />
              <p>{{ $t('暂无数据') }}</p>
            </div>
          </div>
        </div>
      </div>
    </el-col>
    <el-col :span="12">
      <div class="box">
        <div class="area-header">
          <span class="area-header-title">{{ $t('项目现金流') }}</span>
          <el-link :underline="false" style="float: right;margin: 4px 0 0 10px;" @click="cashflowAdd">
            <i class="el-icon-plus" style="color: #007eff;" />
          </el-link>
          <div class="chartBtn">
            <el-select v-model="cashFlow" size="mini" style="width: 100px;margin-top: -4px;" @change="cashflowQuarterOrMonthChange">
              <el-option :label="$t('按月统计')" value="month" />
              <el-option :label="$t('按季统计')" value="season" />
            </el-select>
          </div>
        </div>
        <div class="text item" style="height: 300px;">
          <barLineChart v-if="optionData.datas.length > 0" height="100%" :chart-data="optionData" />
          <div v-else class="noneData">
            <div>
              <svg-icon icon-class="none" class-name="none-icon" />
              <p>{{ $t('暂无数据') }}</p>
            </div>
          </div>
        </div>
      </div>
    </el-col>
    <el-col :span="12">
      <div class="box">
        <!--关键条款-->
        <Terms ref="refTerms" :business-id="businessId" />
      </div>
    </el-col>
    <el-col :span="12">
      <div class="box">
        <div class="area-header">
          <span class="area-header-title">{{ $t('重大事项') }}</span>
        </div>
        <div class="text item none-info">
          <deal-matters-info ref="dealMattersInfo" :buss-id="businessId" />
        </div>
      </div>
    </el-col>
    <el-col :span="24">
      <otherInvestment ref="otherInvestment" />
    </el-col>
    <el-col :span="12">
      <div class="box">
        <div class="area-header">
          <span class="area-header-title">{{ $t('新闻舆情') }}</span>
        </div>
        <div class="text item none-info">
          <company-news-info ref="companyNewsInfo" :buss-id="companyId" />
        </div>
      </div>
    </el-col>
    <el-col :span="12">
      <div class="box">
        <div class="area-header">
          <span class="area-header-title">{{ $t('项目最新事件') }}</span>
        </div>
        <div style="height: 568px;">
          <dealEvent ref="dealEvent" :deal-id="businessId" />
        </div>
      </div>
    </el-col>
    <el-dialog :title="$t('项目估值')" :visible.sync="valuationOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <dealDebtValuationForm ref="dealDebtValuationForm" />
    </el-dialog>
    <el-dialog :title="$t('现金流')" :visible.sync="cashflowOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <dealCashflowForm ref="dealCashflowForm" />
    </el-dialog>
  </el-row>
</template>
<script>
import dealDebtValuationForm from '@/views/deal/valuation/dealDebtValuationForm'
import dealCashflowForm from '@/views/deal/cashflow/dealCashflowForm'
import Terms from '@/components/Terms'
import otherInvestment from '@/components/Deal/otherInvestment'
import { companyInfo } from '@/components/Deal'
import CompanyNewsInfo from '@/components/Deal/companyNewsInfo'
import dealEvent from '@/components/dealEvent'
import dealServicingPlanInfo from '@/components/Deal/dealServicingPlanInfo'
import dealServicingInfo from '@/components/Deal/dealServicingInfo'
import dealMattersInfo from '@/components/Deal/dealMattersInfo'
import { valuationChart } from '@/api/deal/valuation/dealDebtValuation'
import { cashFlowCharts } from '@/api/deal/cashflow/dealCashflow'
import lineChart from '@/views/chart/lineChart.vue'
import barLineChart from '@/views/chart/barLineChart.vue'
export default {
  components: {
    dealDebtValuationForm,
    dealCashflowForm,
    companyInfo,
    CompanyNewsInfo,
    dealServicingPlanInfo,
    dealServicingInfo,
    dealMattersInfo,
    Terms,
    otherInvestment,
    dealEvent,
    lineChart,
    barLineChart
  },
  props: {
    busId: {
      type: String,
      default: () => ''
    },
    busType: {
      type: String,
      default: () => ''
    },
    childLeftMenu: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      statistical: 'month',
      cashFlow: 'month',
      companyId: this.$route.query.companyId,
      businessId: this.$route.query.id,
      // 关键条款弹出层
      dealTermsOpen: false,
      valuationOpen: false,
      cashflowOpen: false,
      chartData: {
        legend: true,
        datas: []
      },
      optionData: {
        legend: true,
        valueFormatter: true,
        datas: []
      }
    }
  },
  created() {
  },
  mounted() {
    this.valuationHandler('month')
    this.cashflowQuarterOrMonthChange('month')
  },
  methods: {
    cashflowAdd() {
      this.cashflowOpen = true
      this.$nextTick(() => {
          this.$refs.dealCashflowForm.init(null)
      })
    },
    // 新增估值
    addDebtValuation() {
      this.valuationOpen = true
      this.$nextTick(() => {
        this.$refs.dealDebtValuationForm.init()
      })
    },
    valuationHandler(val) { // 估值信息图表
      let flag = false
      if (val === 'month') {
        flag = true
      }
      const params = {
        dealId: this.$route.query.id,
        quarterOrMonth: flag
      }
      valuationChart(params).then(response => {
        this.chartData.xLabel = []
        this.chartData.datas = []
        if (response.data != null) {
          this.chartData.xLabel = response.data.dateList
          this.chartData.valueFormatter = true
          this.chartData.datas = [
            {
              name: window.i18n.t('项目估值'),
              data: response.data.projectValuationList
            }
          ]
        }
      })
    },
    cashflowQuarterOrMonthChange(val) { // 项目现金流图表
      let flag = false
      if (val === 'month') {
        flag = true
      }
      const params = {
        dealId: this.$route.query.id,
        quarterOrMonth: flag
      }
      cashFlowCharts(params).then(response => {
        this.optionData = {
          legend: true,
          datas: [],
          yAxis2: false,
          yAxisName2: ' ',
          valueFormatter: true,
          xLabel: []
        }
        if (response.data != null) {
          this.optionData.xLabel = response.data.dateList
          this.optionData.datas = [
            {
              name: this.$t('正现金流'),
              type: 'bar',
              stack: '1',
              data: response.data.positiveCashFlowList
            },
            {
              name: this.$t('负现金流'),
              type: 'bar',
              stack: '1',
              data: response.data.negativeCashFlowList
            },
            {
              name: this.$t('现金流结余'),
              type: 'line',
              stack: '1',
              yAxisIndex: 0,
              data: response.data.cashFlowBalanceList
            }
          ]
        }
      })
    },
    openTermsTemplate() {
      this.$refs.refTerms.getListTerms()
    },
    openNews(row) {
      if (row.newUrl.indexOf('http://') !== -1) {
        window.open(row.newUrl)
      } else if (row.newUrl.indexOf('https://') !== -1) {
        window.open(row.newUrl)
      } else {
        window.open('http://' + row.newUrl)
      }
    }
  }
}
</script>

<style scoped>

.el-container{
  height: 100%;display: flex;
}
.fundMenu{
  top: 70px;
}
.voteMain{
  position: fixed;
  left: 200px;
  right: 0;
  bottom: 0;
  top: 60px;
  overflow: auto;
}
.box-card{
  margin-bottom: 20px;
}
.diyMain{
  margin-left: 200px;
}
.voteMain{
  padding: 20px;
}
.timeLine{
  overflow-y: auto;height: 370px; padding-left: 2px;
}

</style>
